package cate.game.admin.menu.pvp;

import cate.common.util.GameResult;
import cate.game.GameBody;
import cate.game.admin.menu.MenuSetup;
import cate.game.framework.advanced.AdvancedLongAttributes;
import cate.game.pvp.eliterace.EliteRaceDataManager;
import cate.game.pvp.eliterace.data.EliteRaceKV;
import cate.game.pvp.eliterace.support.EliteRaceGMSupport;
import cate.game.pvp.pointrace.PointRaceDataManager;
import cate.game.pvp.pointrace.PointRaceMessagingModule;
import cate.game.pvp.pointrace.data.PointRaceKV;
import cate.game.pvp.pointrace.support.PointRaceGMSupport;

public class PvpMenu extends MenuSetup {

    public PvpMenu(GameBody game) {
        super("pvp");

        reg(game, "组队竞技挑战次数满上", 0, "", (role, params) -> {
            GameResult<Void> r = game.pvp.teamPvp.gmResetChallengeTimes(role.getUid());
            role.getGame().notice.message(role, r);
        });

        reg(game, "积分赛本服启动重置时间", 0, "", (role, params) -> {
            PointRaceDataManager dataManager = role.getGame().pvp.pointRace.getDataManager();
            PointRaceKV kv = dataManager.getData();
            AdvancedLongAttributes attributes = kv.getGmSupport().getAttributes();
            attributes.setAttribute(PointRaceGMSupport.RESET_LOCAL_TIME_MASK);
        });

        reg(game, "积分赛跨服启动重置时间", 0, "", (role, params) -> {
            PointRaceMessagingModule messagingModule = role.getGame().pvp.pointRace.getMessagingModule();
            messagingModule.gmOperation(PointRaceGMSupport.RESET_REMOTE_TIME_TASK);
        });

        reg(game, "积分赛本服清除数据", 0, "", (role, params) -> {
            PointRaceDataManager dataManager = role.getGame().pvp.pointRace.getDataManager();
            dataManager.clear();
            PointRaceKV kv = dataManager.getData();
            kv.getPsData().clear();
            kv.getRankData().clear();
            kv.getRecords().clear();
            kv.getAttributes().clear();
            kv.getEventAttributes().clear();
            kv.getGmSupport().getAttributes().clear();
        });

        reg(game, "积分赛跨服清除数据", 0, "", (role, params) -> {
            PointRaceMessagingModule messagingModule = role.getGame().pvp.pointRace.getMessagingModule();
            messagingModule.gmClearData();
        });

        reg(game, "精英赛本服启动重置时间", 0, "", (role, params) -> {
            EliteRaceDataManager dataManager = role.getGame().pvp.eliteRace.getDataManager();
            EliteRaceKV kv = dataManager.getData();
            AdvancedLongAttributes attributes = kv.getGmSupport().getAttributes();
            attributes.setAttribute(EliteRaceGMSupport.RESET_LOCAL_TIME_MASK);
        });

        reg(game, "精英赛本服清除数据", 0, "", (role, params) -> {
            EliteRaceDataManager dataManager = role.getGame().pvp.eliteRace.getDataManager();
            dataManager.clear();
            EliteRaceKV kv = dataManager.getData();
            role.getGame().pvp.eliteRace.getDataManager().getData().getRankData().clear();
            kv.getAttributes().clear();
            kv.getEventAttributes().clear();
            kv.getGmSupport().getAttributes().clear();
        });

        reg(game, "积分赛本服重新加载机器人", 0, "", (role, params) -> {
            role.getGame().pvp.pointRace.getDataManager().gmRebuildPsData();
            role.getGame().pvp.eliteRace.getDataManager().getRankHandler().sortRankThenUpdateIndex();
        });

        reg(game, "积分赛清除我的数据", 0, "", (role, params) -> {
            role.getPvp().pointRace.clearData();
            role.getPvp().pointRace.season = 1;
            role.getPvp().pointRace.points = 1000L;
        });

        reg(game, "精英赛银币", 1, "数量", (role, params) -> {
            long coins = Long.parseLong(params.get(0));
            role.getPvp().eliteRace.betPO.addCoins(coins);
        });

        reg(game, "精英赛清除红包数据", 0, "", (role, params) -> {
            role.getPvp().eliteRace.redPacketPO.gotSet.clear();
        });

        reg(game, "公会战玩家数据重制", 0, "", (role, params) -> {
            role.getPvp().guildWar.onDaySpan(true);
            game.notice.message(role, "成功");
        });

        reg(game, "公会战设置公会积分", 1, "参数1：积分", (role, params) -> {
            role.getRes().guild.getGuild().war.setPoint(toInt(params, 0, 1000));
            game.notice.message(role, "成功");
        });
    }
}
